<template>
  <div class="container">
    <div>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="所属街道：">
              <el-select
                v-model="form.streetClient"
                style="width: 220px"
                placeholder="请选择"
                @change="getCommunityTeamList"
                clearable
              >
                <el-option
                  v-for="item in streetTeamList"
                  :key="item.CLIENT_NO"
                  :label="item.CLIENT_NAME"
                  :value="item.CLIENT_NO"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="所属社区：">
              <el-select
                v-model="form.communityClient"
                style="width: 210px"
                placeholder="请选择"
                @change="getVillageTeamList"
                clearable
              >
                <el-option
                  v-for="item in communityTeamList"
                  :key="item.CLIENT_NO"
                  :label="item.CLIENT_NAME"
                  :value="item.CLIENT_NO"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="所属小区：">
              <el-select
                v-model="form.villageClient"
                style="width: 220px"
                placeholder="请选择"
                @change="getRoomTeamList"
                clearable
              >
                <el-option
                  v-for="item in villageTeamList"
                  :key="item.CLIENT_NO"
                  :label="item.CLIENT_NAME"
                  :value="item.CLIENT_NO"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-form>
        </el-col>
      </el-row>
      <el-row :gutter="20">
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="作业日期：">
              <el-date-picker
                v-model="form.Date"
                type="date"
                placeholder="选择日期"
                value-format="yyyy-MM-dd"
              ></el-date-picker>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="6">
          <el-form ref="form" :model="form">
            <el-form-item label="点位名称：">
              <el-input v-model="form.Name" style="width: 210px"></el-input>
            </el-form-item>
          </el-form>
        </el-col>
        <el-col :span="4">
          <el-form ref="form" :model="form" style="float: left">
            <el-button size="mini" type="primary" @click="getlistdata"
              >查 询</el-button
            >
            <el-button size="mini" type="success" @click="exportExcel"
              >导 出</el-button
            >
          </el-form>
        </el-col>
      </el-row>
    </div>
    <el-table
      highlight-current-row
      v-loading="loading"
      :data="
        tableData.slice((currentPage - 1) * pageSize, currentPage * pageSize)
      "
      border
    >
      <el-table-column
        prop="LICENSE_PLATE"
        label="垃圾点名称"
        align="center"
        width="200"
      ></el-table-column>
      <el-table-column
        prop="RoadName"
        label="垃圾桶名称"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="CLIENT_NAME"
        label="所属区域"
        align="center"
        width="200"
      ></el-table-column>
      <el-table-column
        prop="WTime"
        label="停留时间"
        align="center"
        width="170"
      ></el-table-column>
      <el-table-column
        prop="WORKDATE"
        label="作业日期"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="SD"
        label="开始时间"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="ED"
        label="结束时间"
        align="center"
      ></el-table-column>
      <!-- <el-table-column label="操作" width="100">
        <template slot-scope="scope">
          <el-button type="text" icon="el-icon-info" @click="handleEdit(scope.$index, scope.row)">详情</el-button>
        </template>
      </el-table-column>-->
    </el-table>
    <div class="pagination">
      <el-pagination
        background
        layout="total, sizes, prev, pager, next, jumper"
        :current-page="currentPage"
        :page-size="pageSize"
        :total="tableData.length"
        @size-change="handleSizeChange"
        @current-change="handlePageChange"
      ></el-pagination>
    </div>
  </div>
</template>
<script>
import '@/assets/css/common.css'
import { formatDate } from '@/common/js/date.js'
import export2Excel from '@/utils/exportExcel/index.js'
export default {
  data () {
    return {
      currentPage: 1, //初始页
      pageSize: 10,    //    每页的数据
      loading: false,
      form: {
        Date: formatDate(new Date(new Date() - 3600 * 1000 * 24), 'yyyy-MM-dd'),
        Name: '',
        communityClient: '',
      },
      streetTeamList: [],
      communityTeamList: [],
      villageTeamList: [],
      // teamList: [{ "CLIENT_NAME": "机扫车" }, { "CLIENT_NAME": "垃圾车" }],
      // teamValue: '机扫车',
      tableData: [],
      originalData: []
    }
  },
  created () {
    this.getlistdata()
    this.getStreetTeamList()
  },
  methods: {
    async getlistdata () {
      this.currentPage = 1;
      this.loading = true
      if (this.form.communityClient !== null) {
        var url = 'RubbishClassification/GetRubbishScoreWorkPoint?ClientNo=' + this.form.communityClient + '&date=' + this.form.Date
      } else {
        var url = 'RubbishClassification/GetRubbishScoreWorkPoint?ClientNo=' + localStorage.getItem('CLIENT_NO') + '&date=' + this.form.Date
      } const { data } = await this.$Http.get(url)
      this.tableData = data
      if (this.form.Name) this.tableData = this.tableData.filter(item => item.LICENSE_PLATE.includes(this.form.Name))
      this.loading = false
    },
    // 获取街道信息
    async getStreetTeamList () {
      const { data } = await this.$Http.get('/RubbishClassification/GetRubbishScoreManageStreet?ClientNo=' + localStorage.getItem('CLIENT_NO'))
      this.streetTeamList = data
    },
    // 获取社区信息
    async getCommunityTeamList () {
      const { data } = await this.$Http.get('/RubbishClassification/GetRubbishScoreManageCommunity?ClientNo=' + this.form.streetClient)
      this.communityTeamList = data
      // }
    },
    // 获取小区信息
    async getVillageTeamList () {
      const { data } = await this.$Http.get('/RubbishClassification/GetRubbishScoreManageVillage?ClientNo=' + this.form.communityClient)
      this.villageTeamList = data
      // }
    },
    // 导出Excel
    exportExcel () {
      let excelName = '垃圾分类作业点统计垃圾分类作业点统计'
      const tHeader = ['垃圾点名称', '垃圾桶名称', '所属区域', '停留时间', '作业日期', '开始时间', '结束时间']
      const filterVal = ['LICENSE_PLATE', 'RoadName', 'CLIENT_NAME', 'WTime', 'WORKDATE', 'SD', 'ED']
      export2Excel(tHeader, filterVal, this.tableData, excelName)
    },
    //详情
    handleEdit (index, row) {
      //   this.idx = index;
      //   this.form = row;
      //   this.editVisible = true;
    },
    // 分页导航
    handlePageChange (currentPage) {
      this.currentPage = currentPage;
      // console.log(this.currentPage)
      // this.$set(this.query, 'pageIndex', val);
      // this.getData();
    },
    handleSizeChange (size) {
      this.pageSize = size;
      console.log(this.pageSize)
    }
  }
}
</script>
<style>
.content {
  overflow-y: scroll;
}
.el-col-6 {
  min-width: 400px;
  min-height: 50px;
}
.el-table th {
  height: 40px;
}
</style>